package felix.dataviewer.Util;

import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.ResolveInfo;

import java.util.Comparator;

/**
 * Created by huangmf on 7/28/2017.
 */

public class AppCompactor implements Comparator<ResolveInfo> {
    @Override
    public int compare(ResolveInfo info1, ResolveInfo info2) {
        ActivityInfo left = info1.activityInfo;
        ActivityInfo right = info2.activityInfo;
        boolean leftIsSystem = isSystem(left.applicationInfo.flags);
        boolean rightIsSystem = isSystem(right.applicationInfo.flags);
        if (leftIsSystem ^ rightIsSystem) {
            return leftIsSystem ? -1 : 1;
        }
        return 0;
    }

    private boolean isSystem(int flag) {
        return (flag & ApplicationInfo.FLAG_SYSTEM) != 0;
    }
}
